package org.util.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipUtil {


	public static void zipFiles(File[] srcfile, File zipfile) {
		byte[] buf = new byte[1024];
		try {
			// ZipOutputStream类：完成文件或文件夹的压缩
			ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
			for (int i = 0; i < srcfile.length; i++) {
				FileInputStream in = new FileInputStream(srcfile[i]);
				out.putNextEntry(new ZipEntry(srcfile[i].getName()));
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}
				out.closeEntry();
				in.close();
			}
			out.close();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/*public static void main(String[] args) {
		try {
			ZipUtil.zipFiles(new File[]{new File("E:\\workspace\\apache-tomcat-7.0.23\\webapps\\timeline-parent\\timeline-transform\\t1.csv"),new File("E:\\workspace\\apache-tomcat-7.0.23\\webapps\\timeline-parent\\timeline-transform\\t2.csv")},
					new File("E:\\workspace\\apache-tomcat-7.0.23\\webapps\\timeline-parent\\timeline-transform\\tzip.zip"));
			//ZipUtil.zip("E:\\workspace\\apache-tomcat-7.0.23\\webapps\\timeline-parent\\timeline-transform\\t2.csv",
				//	"E:\\workspace\\apache-tomcat-7.0.23\\webapps\\timeline-parent\\timeline-transform\\tzip.zip");
			// ZipUtil.unzip("D:\\a\\010108012008-8-25.zip", "d:\\a\\tmp");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}*/

}
